package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.MyOrderInfoBean1;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import androidx.annotation.Nullable;

/**
 * Created by Administrator on 2018/11/23.
 */

public class MyOrderInfoAdapter1 extends BaseQuickAdapter<MyOrderInfoBean1.OrdermapBean.ProdcutListBean.ListsEntitiesBean, BaseViewHolder> {
    private int beanType;
    private int state;
    private int type;
    private long day;

    public MyOrderInfoAdapter1(@Nullable List<MyOrderInfoBean1.OrdermapBean.ProdcutListBean.ListsEntitiesBean> data, int state, int type, int beanType) {
        super(R.layout.view_item_my_order_info, data);
        this.state = state;

        this.type = type;
        this.beanType = beanType;
    }

    @Override
    protected void convert(BaseViewHolder helper, MyOrderInfoBean1.OrdermapBean.ProdcutListBean.ListsEntitiesBean item) {

        helper.addOnClickListener(R.id.btn_refund);
        if (beanType == 0) {
            if (type != 2) {
                if (item.getState() == 0) {
                    helper.setText(R.id.btn_type, "dsadasd");
                    helper.setGone(R.id.btn_type, false);
                } else if (item.getState() == 1) {
                    helper.setText(R.id.btn_type, "退款中");
                    helper.setGone(R.id.btn_type, true);
                } else if (item.getState() == 2) {
                    helper.setText(R.id.btn_type, "已退款");
                    helper.setGone(R.id.btn_type, true);
                } else {
                    helper.setText(R.id.btn_type, "退款失败");
                    helper.setGone(R.id.btn_type, true);
                }
                if (state == 1 /*&& type != 1*/ || state == 2 /*&& type != 1*/ || state == 5 && day < 7) {
                    if (item.getState() != 0) {
                        helper.setGone(R.id.btn_refund, false);
                    } else {
                        helper.setGone(R.id.btn_refund, true);
                    }

                } else {
                    helper.setGone(R.id.btn_refund, false);

                }
            } else {
                helper.setGone(R.id.btn_refund, false);
                helper.setGone(R.id.btn_type, false);
            }
        } else {
            helper.setGone(R.id.btn_refund, false);
            helper.setGone(R.id.btn_type, false);
        }
        if(item.getState()==2)
        {
            helper.setText(R.id.tv_status, "已发货");
            helper.setGone(R.id.tv_status, true);
        } else if(item.getState()==1){
            helper.setText(R.id.tv_status, "未发货");
            helper.setGone(R.id.tv_status, true);
        }else {
            helper.setGone(R.id.tv_status, false);
        }
        ImageView ivIcon = helper.getView(R.id.iv_icon);

        helper.setText(R.id.tv_title, item.getProduct_name())
                .setText(R.id.tv_info, "null".equals(item.getArrribute_name()) ? "" : item.getArrribute_name())
                .setText(R.id.tv_count, "×" + item.getNum());
        if (type == 1) {
            helper.setText(R.id.tv_money, getPrice(item) + "欧花");
            helper.setGone(R.id.tv_rmb_fh,false);
        }else {
            helper.setText(R.id.tv_money, getPrice(item));
            helper.setGone(R.id.tv_rmb_fh,true);
        }

        String img_zt = "";
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] splitImgZt = item.getImg_zt().split(",");
            if (splitImgZt.length > 0) {
                img_zt = splitImgZt[0];
            }
        }
        GlideUtils.loadRoundImg(mContext, ivIcon, img_zt, R.mipmap.default_foods_icon, 4);
//        if (!TextUtils.isEmpty(item.getImg_zt())) {
//            final String[] split = item.getImg_zt().split(",");
//            Glide.with(mContext).load(split[0]).into(ivIcon);
//        } else {
//            GlideUtils.loadImg(mContext, ivIcon, R.mipmap.logo);
//        }
    }

    @NotNull
    private String getPrice(MyOrderInfoBean1.OrdermapBean.ProdcutListBean.ListsEntitiesBean item) {
        String price = "";
        if (!TextUtils.isEmpty(item.getPrice()) && Double.parseDouble(item.getPrice()) != 0.00) {
            price += "";
            price += item.getPrice();

        }
        if (!TextUtils.isEmpty(item.getMarket_price()) && Double.parseDouble(item.getMarket_price()) != 0.00) {
            if (!TextUtils.isEmpty(price)) {
                price += "+";
                price += item.getMarket_price();
                price += "积分";
            } else {
                price += item.getMarket_price();
                price += "积分";
            }
        }
        if (TextUtils.isEmpty(price)) {
            price = "0.00";
        }

        return price;
    }

    public void setTime(long day) {
        this.day = day;
    }
}
